//
//  CHProgressHUD.m
//  SZTZ
//
//  Created by 陈浩 on 2017/3/7.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHProgressHUD.h"
@interface CHProgressHUD ()<UIAlertViewDelegate>

@property (nonatomic ,strong) UIButton *coverBtn;
@end
@implementation CHProgressHUD

+(void)showSuccess:(NSString *)success{
 

    
    
}





+(void)showError:(NSString *)error{
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    CHProgressHUD *progressHUD = [[CHProgressHUD alloc] initWithFrame:CGRectMake(0, 0, 150, 44) withTitle:error];
    progressHUD.layer.cornerRadius = 5;
    progressHUD.layer.masksToBounds = YES;
    progressHUD.center = window.center;
    [window addSubview:progressHUD];

}


-(instancetype)initWithFrame:(CGRect)frame withTitle:(NSString *)title{
    if (self = [super initWithFrame:frame]) {
        
        
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        UIButton *coverBtn = [[UIButton alloc] initWithFrame:window.bounds];
        [window addSubview:coverBtn];
        self.coverBtn = coverBtn;
        self.backgroundColor = [UIColor blackColor];
        self.alpha = 0.7;
        UILabel *titleLable = [[UILabel alloc] initWithFrame:self.bounds];
        titleLable.textAlignment = NSTextAlignmentCenter;
        titleLable.textColor = [UIColor whiteColor];
        titleLable.font = [UIFont systemFontOfSize:14];
        titleLable.text = title;
        [self addSubview:titleLable];
        [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(dismiss) userInfo:self repeats:NO];
        
    }
    return self;
}

-(void)dismiss{
    
    [self removeFromSuperview];
    [self.coverBtn removeFromSuperview];
}


@end
